import emas from '@csair/windvane-api-ehome'
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import Vant from 'vant'
import msg from './assets/js/toast'
import api from './api/index'
import VueI18n from 'vue-i18n'
import fastClick from 'fastclick'
import 'vant/lib/index.css'
import './plugins/element.js'
import './utils/direction.js'
//引入 解决移动端300s延迟
fastClick.attach(document.body)

/*
let ua = window.navigator.userAgent
if(!!ua.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)){
  // ios端
  //初始化FastClick实例。在页面的DOM文档加载完成后
  sessionStorage.setItem('system', 'ios')
}
else if(ua.indexOf('Android') > -1 || ua.indexOf('Adr') > -1) {
  // android端
  sessionStorage.setItem('system', 'android')
}
*/
Vue.config.productionTip = false

Vue.use(Vant)
Vue.use(VueI18n)

Vue.prototype.$api = api
Vue.config.productionTip = false
Vue.prototype.$msg = msg

// 语言设置
let lang = sessionStorage.getItem('language')
let language = lang ? lang : sessionStorage.setItem('language','zh-CN')
const i18n = new VueI18n({
  locale: language ? language : 'zh-CN',    // 语言标识
  //this.$i18n.locale // 通过切换locale的值来实现语言切换
  messages: {
    'zh-CN': require('./lang/zh'),   // 中文语言包
    'en-US': require('./lang/en')    // 英文语言包
  }
})

// 如果不是生产环境则开启调试
if (process.env.NODE_ENV !== 'production') {
  new VConsole()
}

// 延迟获取emas token
setTimeout(() => {
  // 兼容刘海屏
  const obj = {
    iPhoneXStyle: 'Bool',
    adaptNaviHeight: 'float',
    adaptTabHeight: 'float'
  }
  emas
    .EmasInformation
    .getInformation(obj)
    .then(result => {
      window.sessionStorage.setItem('token', result.token)
      if (result.language !== 'zh') {
        this.$i18n.locale = 'en-US'
      } else {
        this.$i18n.locale = 'zh-CN'
      }
      console.log(result, 123)
    })
}, 0)

new Vue({
  router,
  i18n,
	store,
	render: (h) => h(App),
}).$mount('#app');

